Treat <value> tags with no type tag inside as if they were strings (as required
authorEwan Mellor <ewan@xensource.com>
Fri, 5 Jan 2007 12:30:32 +0000 (12:30 +0000)
committerEwan Mellor <ewan@xensource.com>
Fri, 5 Jan 2007 12:30:32 +0000 (12:30 +0000)
by the XML-RPC spec).

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/libxen/src/xen_common.c

index c380b851908f7c2aa40442b07aac8a8fc659dba3..9834565ff0be668da7fc3312ca65474d7ec70576 100644 (file)
@@ -373,11 +373,18 @@ static void server_error_2(xen_session *session, const char *error_string,
 }
 
 
-static bool is_container_node(xmlNode *n, char *type)
+static bool is_node(xmlNode *n, char *type)
 {
     return
         n->type == XML_ELEMENT_NODE &&
-        0 == strcmp((char *)n->name, type) &&
+        0 == strcmp((char *)n->name, type);
+}
+
+
+static bool is_container_node(xmlNode *n, char *type)
+{
+    return
+        is_node(n, type) &&
         n->children != NULL &&
         n->children == n->last &&
         n->children->type == XML_ELEMENT_NODE;
@@ -390,13 +397,30 @@ static bool is_container_node(xmlNode *n, char *type)
  */
 static xmlChar *string_from_value(xmlNode *n, char *type)
 {
-    return
-        is_container_node(n, "value") &&
-        0 == strcmp((char *)n->children->name, type) ?
-          (n->children->children == NULL ?
-             xmlStrdup(BAD_CAST("")) :
-             xmlNodeGetContent(n->children->children)) :
-          NULL;
+    /*
+      <value><type>XYZ</type></value> is normal, but the XML-RPC spec also
+      allows <value>XYZ</value> where XYZ is to be interpreted as a string.
+    */
+
+    if (is_container_node(n, "value") &&
+        0 == strcmp((char *)n->children->name, type))
+    {
+        return
+            n->children->children == NULL ?
+                xmlStrdup(BAD_CAST("")) :
+                xmlNodeGetContent(n->children->children);
+    }
+    else if (0 == strcmp(type, "string") && is_node(n, "value"))
+    {
+        return
+            n->children == NULL ?
+                xmlStrdup(BAD_CAST("")) :
+                xmlNodeGetContent(n->children);
+    }
+    else
+    {
+        return NULL;
+    }
 }